package com.ky.tms.controller;


import com.ky.tms.entity.TmsDriver;
import com.ky.tms.entity.TmsUser;
import com.ky.tms.service.ITmsDriverService;
import com.ky.tms.util.CommonResult;
import com.ky.tms.util.JwtUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chengkaimao
 * @since 2020-04-14
 */
@RestController
@RequestMapping("/tms/tms-driver")
public class TmsDriverController {

    @Autowired
    private ITmsDriverService tmsDriverService;

    @ApiOperation("司机数据分页")
    @GetMapping("page")
    public CommonResult page(TmsDriver tmsDriver, @RequestParam Long pageSize, @RequestParam Long current, HttpServletRequest request){
        String userName = JwtUtil.getUserName(request);
        return CommonResult.buildSuccess(tmsDriverService.page(userName, tmsDriver, pageSize, current));
    }

    @ApiOperation("创建司机")
    @PostMapping
    public CommonResult add(@RequestBody TmsDriver tmsDriver, HttpServletRequest request){
        String userName = JwtUtil.getUserName(request);
        tmsDriverService.add(userName,tmsDriver);
        return CommonResult.buildSuccess(null);
    }

    @ApiOperation("修改司机")
    @PutMapping
    public CommonResult update(@RequestBody TmsDriver tmsDriver, HttpServletRequest request){
        String userName = JwtUtil.getUserName(request);
        tmsDriverService.update(userName,tmsDriver);
        return CommonResult.buildSuccess(null);
    }

    @ApiOperation("删除司机")
    @DeleteMapping
    public CommonResult delete(@RequestBody List<Long> ids, HttpServletRequest request){
        String userName = JwtUtil.getUserName(request);
        tmsDriverService.delete(userName, ids);
        return CommonResult.buildSuccess(null);
    }

    @ApiOperation("搜索下拉数据")
    @GetMapping("select-list")
    public CommonResult selectList(TmsDriver tmsDriver, HttpServletRequest request) {
        return CommonResult.buildSuccess(tmsDriverService.selectList(tmsDriver));
    }

}
